package main

import (
	"fmt"
	"strconv"
)

func main() {
	left1 := &TreeNode{2, nil, nil}
	//right1 := &TreeNode{3, nil, nil}
	tree1 := &TreeNode{1, left1, nil}

	//left2 := &TreeNode{1, nil, nil}
	right2 := &TreeNode{2, nil, nil}
	tree2 := &TreeNode{1, nil, right2}

	same := isSameTree(tree1, tree2)
	fmt.Println(same)
}

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func isSameTree(p *TreeNode, q *TreeNode) bool {
	arr1 := pre_order_traversal(p)
	arr2 := pre_order_traversal(q)

	fmt.Println(arr1)
	fmt.Println(arr2)

	len1 := len(arr1)
	len2 := len(arr2)

	if len1 != len2 {
		return false
	}
	for i := 0; i < len1; i++ {
		if arr1[i] != arr2[i] {
			return false
		}
	}
	return true
}

func pre_order_traversal(t *TreeNode) []string {
	var arr = []string{}
	if t == nil {
		return arr
	}
	arr = append(arr, strconv.Itoa(t.Val))
	if t.Left != nil {
		arr = append(arr, pre_order_traversal(t.Left)...)
	}
	if t.Right != nil {
		arr = append(arr, pre_order_traversal(t.Right)...)
	}
	if t.Left == nil && t.Right != nil {
		arr = append(arr, "null")
	}

	return arr
}



